﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DeviceManager.DataAccessLayer;
using DeviceManager.BusinessLogicLayer;

namespace DeviceManagementIT.Formain.AccountManager
{
    public partial class frmAddAccount : DevExpress.XtraEditors.XtraForm
    {
        AccountBllOperation accountbll = new AccountBllOperation();
        NGUOIDUNG account;
        bool checkaccount = false;
        public frmAddAccount()
        {
            InitializeComponent();
        }

        private void btnSaveAccount_Click(object sender, EventArgs e)
        {
            if (checkaccount)
            {
                account = new NGUOIDUNG();
                account.TaiKhoan = txtAccount.Text;
                if (txtPass.Text == txtRepass.Text)
                    account.MatKhau = txtPass.Text;
                else
                    MessageBox.Show("Mật khẩu không trùng khớp!", "Message");
                string message = accountbll.SaveRecordUnit(account);
                MessageBox.Show(message, "Message");
            }
        }

        private void btnCheckAccount_Click(object sender, EventArgs e)
        {
            NHANVIEN nhanvien = new NHANVIEN();
            nhanvien.MaNV = txtMaNV.Text;
            PeopleBllOperation peoplebll = new PeopleBllOperation();
            List<NHANVIEN> peoplelist = new List<NHANVIEN>();
            peoplelist = peoplebll.GetRecordUnit(nhanvien);
            if (peoplelist.Count == 0)
            {
                checkaccount = false;
                MessageBox.Show("Mã nhân viên không tồn tại!", "Thông báo");
            }
            else
                checkaccount = true;
        }

        private void txtMaNV_EditValueChanged(object sender, EventArgs e)
        {
            txtAccount.Text = txtMaNV.Text;
        }
    }
}